05. Else If Statements
In some situations, two conditionals aren’t enough. Consider the following situation.
You're trying to decide what to wear tomorrow. If it is going to snow, then you’ll want to wear a coat. If it's not going to snow and it's going to rain, then you’ll want to wear a jacket. And if it's not going to snow or rain, then you’ll just wear what you have on.
Else if statements
In JavaScript, you can represent this secondary check by using an extra if statement called an else if statement.
var weather = "sunny";
if (weather === "snow") {
console.log("Bring a coat.");
} else if (weather === "rain") {
console.log("Bring a rain jacket.");
} else {
console.log("Wear what you have on.");
}
Prints: Wear what you have on.
By adding the extra else if
statement, you're adding an extra conditional statement.
If it’s not going to snow, then the code will jump to the else if
statement to see if it’s going to rain.
If it’s not going to rain, then the code will jump to the else
statement.
The else
statement essentially acts as the "default" condition in case all the other if
statements are false.
Follow The Conditional Logic 1
SOLUTION:
"You paid the exact amount, have a nice day!"Follow The Conditional Logic 2